<?php

namespace App\Jobs;

use App\Http\Controllers\Api\StarController;
use App\Models\Article;
use App\Models\Star;
use App\Models\User;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Http\Request;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Storage;

class DelAttachJob implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    private $file_path;
    /**
     * RandStarJob constructor.
     * @param $article_id
     */
    public function __construct($file_path)
    {
        $this->file_path = $file_path;
    }

    /**
     * @throws \App\Exceptions\BlackException
     * @throws \Illuminate\Validation\ValidationException
     * @throws \Throwable
     */
    public function handle()
    {
        \Log::info('--start-delete-attach--');
        $disk = Storage::disk('qiniu');
        $old_short_url= ltrim($this->file_path, env('QINIU_URL'));
        $disk->delete($old_short_url);
        \Log::info('--end-delete-attach--');
    }
}
